using System.Collections;
using SharpGraphT.Sharp.Sharp.Util;

namespace SharpGraphT.Util;

public class LiveEnumerableWrapper<TE> : IEnumerable<TE> {
    private Func<IEnumerable<TE>> _supplier;

    public LiveEnumerableWrapper() : this(null) { }

    public LiveEnumerableWrapper(Func<IEnumerable<TE>> supplier) =>
        _supplier = Objects.RequireNonNull(supplier);

    public IEnumerator<TE> GetEnumerator() => _supplier().GetEnumerator();

    public Func<IEnumerable<TE>> Supplier {
        get => _supplier;
        set => _supplier = value;
    }

    IEnumerator IEnumerable.GetEnumerator() {
        return GetEnumerator();
    }
}